import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import api from './api'
// 2. 引入组件样式
import 'vant/lib/index.css';


const app=createApp(App)

// 在实例上绑定属性
app.config.globalProperties.$api=api

//添加路由守卫
router.beforeEach((to, from) => {
        const token = localStorage.getItem('h5_token')
        //非登录页面token不存在
        if (!token && to.path !== '/login') {
            return '/login'
        } else if (token && to.path === '/login') {
            return '/'
        } else {
            return true
        }
    }
)

// 路由挂载
app.use(router)
app.mount('#app')
